<?php session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
require_once "functions.php";
if(isset($_SESSION['lang']))
    require_once "./language_files/postNews_" . $_SESSION['lang'] . ".php";
else
    require_once "./language_files/postNews_en.php";

$member_id=$_SESSION['member_id'];
if(isset($_GET['conference_id']))
{
    $conference_id=intval($_GET['conference_id']);
}
else if(isset($_POST['confID']))
{
    $conference_id=intval($_POST['confID']);
}
$conference_name=get_conference_name($conference_id);
echo"</br><span class=breadcrumbs><a href='subscriberConferencePage.php?conference_id={$conference_id}'>" . $conference_name . "</a>" . " > " . $lang['post_news'] . "</span> </br>";
?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <?php
        include "jquery.php";
//the javescript function that displays the calendar
        ?>
        <link href="jquery-ui-all.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="jquery-ui-1.8.21.custom.min.js"></script>
        <script type="text/javascript">
            $(function() {
                $( "#dd" ).datepicker({ dateFormat: "yy-mm-dd" });
            });
        </script>
        <script type="text/javascript" src="functions.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                check_top();
                $(document).find(":submit").click(function(){

                    $(document).find("form").attr("action", "postNews.php?type=1");

                });
            });

        </script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <link href="style3.css" rel="stylesheet" type="text/css" />
        <title><?php echo $lang['post_news'];?></title>

    </head>
    <body>
        <?// creating the header , the textFields and the buttons     ?>
        <h2><?php echo $lang['post_news'];?></h2>
        <form id="newss" method="post" action ="" >
            <p><strong><?php echo $lang['title'];?></strong><br/>
                <input type ="text" name ="ti" maxlength ="50"/>
            </p>
            <p><strong><?php echo $lang['news'];?></strong></p>
            <p>
                <textarea name="news" cols="75" rows="10"></textarea>
            </p>
            <p><strong>  <?php echo $lang['date'];?> </strong></p>
            <input id="dd" type="text" name="date" maxlength="10" size="26" />
            <p>
                <input name="submit" type="submit" value="<?php echo $lang['post'];?>" />
                <input name="clear" type="reset" value="<?php echo $lang['clear'];?>" />
                <input name="confID" type="hidden" value="<?php echo $conference_id?>"/>
            </p>
        </form>
    </body>
</html>
<?
//check if the user clicked on submit button
if(isset($_GET['type']))
{
// store the textFields values in 3 variables
    $title=mysql_safe($_POST['ti']);
    $news=mysql_safe($_POST['news']);
    $date=$_POST['date'];
    $today=date("Y-m-d");
    $d=strtotime($date);
    $dd=date("Y-m-d",$d);
//check if any of the textfields are empty and display an alert
    if(!$title)
    {
        echo '<script type="text/javascript">',
        'alert("please enter a title");',
        '</script>';
    }
    else
    if(!$news)
    {

        echo '<script type="text/javascript">',
        'alert("Please make sure that the body is not empty");',
        '</script>';
    }
    else
    if(!$date)
    {
        echo '<script type="text/javascript">',
        'alert("Please pick a date");',
        '</script>';
    }
    else if($dd < $today)
    {
        echo '<script type="text/javascript">',
        'alert("Expiary date can not be in the past!");',
        '</script>';
    }

    // if the user enters all the requered data the actions will be performed
    else
    {
        //establish a database connection
//insert into the table the information entered by the user
        $result=mysql_query("INSERT INTO o_postnews_conference(member_id, conference_id , ann_title , ann_deadline , ann_text) VALUES ('$member_id','$conference_id', '$title' , '$date' , '$news')") or die(mysql_error());
        ;
        //check if the query was successful
        if($result)
        {
            //displaying an alert to notify the user that the news has be successfully posted
            echo '<script type="text/javascript">',
            'alert("The news has been successfully posted");',
            '</script>';
        }
        else
        {
            //notify the user that an error occured
            echo '<script type="text/javascript">',
            'alert("There was an error while posting the news, please try again later");',
            '</script>';
        }
    }
}








